<template>
  <view class="user">
    <!-- 头部 -->
    <view class="user-wrap">
      <view class="setting iconfont icon31shezhi"></view>
      <view class="info" v-if="userInfo" @click="toUserInfo">
        <image v-if="userInfo.avatar_url" class="avatar" mode="aspectFill" :src="userInfo.avatar_url"></image>
        <image v-else class="avatar" mode="aspectFill" src="/static/missing-face.png"></image>
        <view class="nickname">{{ userInfo.nickname }}</view>
      </view>
      <view class="info" v-if="!userInfo">
        <view>
          <button open-type="getUserProfile" lang="zh_CN" @click="login">登录</button>
        </view>
      </view>
    </view>

    <!-- 订单状态 -->
    <view class="order-status">
      <view class="status-wrap">
        <!-- 单元格 -->
        <view class="cell">
          <view class="cell-left">
            <image class="cell-icon" src="/static/images/user/icon-order.png" mode="aspectFill"></image>
            <view class="cell-text">我的课程</view>
          </view>
          <view class="iconfont iconmore1"></view>
        </view>

        <!-- 订单状态 -->
        <view class="status-list">
          <view class="status-item" hover-class="btn-hover" v-for="(item, index) in orderStatusList"
                :key="index" @click="xqa(item.path)">
            <view class="item-icon" :class="item.icon"></view>
            <u-icon :name="item.icon" size="48"></u-icon>
            <view class="item-text">{{ item.name }}</view>
          </view>
        </view>
      </view>
    </view>

    <!-- 用户服务 -->
    <view class="com-item">
      <view class="com-wrap">
        <view class="cell" v-for="(item, index) in serverList" :key="index" @click="xqa(item.path)">
          <view class="cell-left">
            <image class="cell-icon" :src="item.icon" mode="aspectFill"></image>
            <view class="cell-text">{{ item.title }}</view>
          </view>
          <view class="iconfont iconmore1"></view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {

  data() {
    return {
      userInfo: null,
      uid: 0,
      xcxcode: '', //获取登录用户的code
      orderStatusList: [{
        name: '我的课程',
        icon: 'file-text',
        status: 10,
        path: '../mycourse/index?id=1'
      },
        {
          name: '我的收藏',
          icon: 'bookmark',
          status: 30,
          path: '../mycourse/index?id=0'
        },
        {
          name: '学习记录',
          icon: 'clock',
          status: 40,
          path: '../mycourse/index?id=2'
        }
      ],
      currentIndex: 0,
      serverList: [{
        title: '客服中心',
        icon: '/static/images/user/icon-kefu.png',
        path: '../xq/index?id=3'
      },
        {
          title: '帮助中心',
          icon: '/static/images/user/icon-help.png',
          path: '../xq/index?id=2'
        },
        {
          title: '用户协议',
          icon: '/static/images/user/icon-about.png',
          path: '../xq/index?id=4'
        }
      ]
    };
  },
  onShow() {
    this.userInfo = uni.getStorageSync('userInfo');
    if (this.userInfo) {
      this.userData()
    }

  },
  methods: {
    //登录
    login() {
      uni.navigateTo({
        url: '/pages/user/login'
      })
    },
    toUserInfo() {
      uni.navigateTo({
        url: '/pages/my/myinfo'
      })
    },
    userData() {
      this.$api.getUserInfo({
        id: this.userInfo.id
      }).then(res => {
        this.userInfo = res
      })
    },
    xqa(v){
    }

  }
};
</script>

<style lang="scss">
page {
  background: #f2f2f2;
}

.btn-hover {
  background: #f2f2f2 !important;
}

.user {
  .user-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50vw;
    padding: 30rpx;
    z-index: 9;
    border-radius: 0 0 20% 20%;
    background-color: #3d9bf6;
    // background: url('https://handsel.oss-cn-shenzhen.aliyuncs.com/1588938371592.jpg') no-repeat;
    background-size: cover;

    .setting {
      color: #fff;
      position: absolute;
      top: 60rpx;
      left: 60rpx;
      font-size: 50rpx;
    }

    .info {
      position: absolute;
      text-align: center;

      .avatar {
        width: 150rpx;
        height: 150rpx;
        border-radius: 50%;
      }

      .nickname {
        color: #fff;
        font-size: 28rpx;
      }
    }
  }

  .order-status {
    padding: 0 20rpx;
    margin-top: -10vw;

    .status-wrap {
      border-radius: 25rpx;
      overflow: hidden;

      .status-list {
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        background: #fff;
        padding-top: 30rpx;
        padding-bottom: 30rpx;

        .status-item {
          flex: 1;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;

          .item-icon {
            line-height: 1;
            font-size: 65rpx;
            color: #bbb;
          }

          .item-text {
            font-size: 28rpx;
            color: #666;
            margin-top: 5rpx;
          }
        }
      }
    }
  }

  .com-item {
    padding-left: 20rpx;
    padding-right: 20rpx;
    margin-top: 20rpx;

    .com-wrap {
      border-radius: 25rpx;
      overflow: hidden;
    }
  }

  .cell {
    height: 80rpx;
    padding-left: 20rpx;
    padding-right: 20rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #f8f8f8;

    &:active {
      background: #f2f2f2;
    }

    &:last-child {
      border-bottom: none !important;
    }

    .cell-left {
      display: flex;
      align-items: center;

      .cell-icon {
        width: 50rpx;
        height: 50rpx;
      }

      .cell-text {
        color: #666;
        font-size: 28rpx;
        margin-left: 20rpx;
      }
    }

    .iconfont {
      font-size: 40rpx;
      color: #999;
    }
  }
}

button {
  background-color: rgba(130, 200, 230, 0.95);
  color: #fff;
  font-size: 30rpx;
  line-height: 30rpx;
  padding: 20rpx 40rpx !important;
  // background-color:transparent;
  box-shadow: 4rpx 4rpx 2rpx rgba(78, 101, 153, 0.4);
}

button::after {
  border: none
}
</style>
